import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * 注意:子菜单只在路由子时出现。长度&gt;= 1
 * 详情见:https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html

＊

*隐藏:true如果设置为true，项目将不会显示在侧边栏(默认为false)

* alwaysShow: true如果设置为true，将始终显示根菜单

*如果没有设置alwaysShow，当item有多个子路由时，

*它将成为嵌套模式，否则不显示根菜单

* redirect: noRedirect如果设置noRedirect将不会在面包屑中重定向

*名称:'router-name'被&lt;(必须设置! !)

* meta: {

角色:['admin'，'editor']控制页面角色(您可以设置多个角色)

标题:' Title '名称显示在侧边栏和面包屑(推荐集)

图标:'svg-name'/'el-icon-x'，该图标显示在侧边栏中

Breadcrumb: false如果设置为false，则该项将隐藏在Breadcrumb中(默认为true)

activeMenu: '/example/list'如果设置了路径，侧边栏会突出显示你设置的路径
  }
 */

// 常量路由
export const constantRoutes = [
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "el-icon-user-solid" },
      },
    ],
  },
  {
    path: "/product",
    component: Layout,
    redirect: "/product",
    meta: {
      title: "商品管理",
      icon: "el-icon-goods",
    },
    children: [
      {
        path: "trademark",
        name: "Trademark",
        meta: {
          title: "品牌管理",
        },
        component: () => import("@/views/product/trademark/trademark"),
      },
    ],
  },

  {
    path: "/root",
    component: Layout,
    redirect: "/menuRoot",
    meta: {
      title: "权限管理",
      icon: "el-icon-lock",
    },
    children: [
      {
        path: "userRoot",
        name: "UserRoot",
        meta: {
          title: "用户管理",
        },
        component: () => import("@/views/root/userRoot/userRoot"),
      },

      {
        path: "menuRoot",
        name: "Menu",
        meta: {
          title: "菜单管理",
        },
        component: () => import("@/views/root/menuRoot/menuRoot"),
      },
    ],
  },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];
// 异步路由
export const asyncRoutes = [];
/* 未匹配路由 */
export const anyRoute = { path: "*", redirect: "/404", hidden: true };
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
